package com.umiwe.permission.mapper;


import com.umiwe.entity.UmiweRole;

import com.umiwe.entity.UserRoleVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
import java.util.Map;


@Mapper
public interface UserRoleMapper {
    /**
     * 通过用户id找到对应角色
     * @param userId
     * @return
     */
    @Select("SELECT uu.id as userId,user_name as userName,uu.dingtalk_id as dingtalkId,uu.china_user_name as chinaUserName,ur.id as roleId,ur.name as roleName,ur.system_id " +
            "as systemId FROM  umiwe_user uu inner JOIN umiwe_user_role uur ON uu.id = uur.user_id inner JOIN umiwe_role ur ON uur.role_id = ur.id and uur.status = 1" +
            " AND ur.is_delete = 2 AND ur.STATUS = 1 WHERE uu.id = #{userId} and ur.system_id = #{systemId}")
    UserRoleVO getUserRoleById(@PathVariable("userId") Integer userId, @PathVariable("systemId")Integer systemId);

    /**
     * 查询用户 所有角色
     * @param userId
     * @return
     */
    @Select("select role_id as roleId,user_id as userId,id,status from umiwe_user_role where user_id = #{userId}")
    List<Map> getUserRoleList(Integer userId);
}
